#!/usr/local/bin/perl

use strict;
use Log::Log4perl;
use lib ("/home/sgetest/lib");
use TIGR::HTCUtils;

my $log_conf = q~
log4perl.rootLogger=DEBUG, client
log4perl.appender.client=Log::Log4perl::Appender::File
log4perl.appender.client.mode=append
log4perl.appender.client.layout=Log::Log4perl::Layout::PatternLayout
log4perl.appender.client.layout.ConversionPattern=%H [%d{MM/dd HH:mm}] %p %M - %m%n
~;


# setup logging
#
my $logfile = "/usr/local/scratch/$ENV{USER}/arr-job-array/submit.log";
$log_conf .= "log4perl.appender.client.filename=$logfile\n";
Log::Log4perl::init(\$log_conf);
my $logger = Log::Log4perl->get_logger(__PACKAGE__);

# Before starting the test, count the perl processes
my $proc_cnt = TIGR::HTCUtils->get_perl_process_count();
#$logger->info("Active perl process count is : $proc_cnt");
print "Active perl process count is : $proc_cnt \n";
if ($proc_cnt > 20) {
        #print "Active perl process count exceeded max limit of 20. Skipping the launch of new test..\n";
        $logger->info("Active perl process count exceeded max limit of 20. Skipping the launch of new test..");
	TIGR::HTCUtils->log_test_skip("test_longsleep");
        exit(1);
}

TIGR::HTCUtils->log_test_start("test_longsleep");
$logger->info("Starting long sleep test.");
my $runCmd = "/home/sgetest/bin/runCmd";
system("$runCmd -c \"/home/$ENV{USER}/bin/longsleep.sh 180\" -o /usr/local/scratch/$ENV{USER}/runcmd_longsleep/longsleep.out -e /usr/local/scratch/$ENV{USER}/runcmd_longsleep/longsleep.err");
my $ret=$?;

TIGR::HTCUtils->log_test_finish("test_longsleep");
$logger->info("Finished run long sleep with return value: $ret");

exit $ret;
